<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小西瓜 <751707632@qq.com.com>
// +----------------------------------------------------------------------
namespace app\fowl\model;

use app\admin\model\RouteModel;
use think\Model;               
use tree\Tree;
use think\Db;
use app\fowl\model\ImsMeetingJoinModel;

class ImsMeetingLiveModel extends Model
{

    protected $type = [
        'more' => 'array',
    ];

    /**
     * 查询会议列表
     * @param array $where 查询条件
     * @param strimg $order 查询顺序
     * @return array
     */
    public function meetingList($where=array(), $order='', $limit=10)
    {
        $model = $this->alias('vm')
        ->join('__PORTAL_CATEGORY__ pc','vm.type_id = pc.id', 'left')
        ->join('__IMS_MEMBER__ im','vm.user_id = im.id', 'left')
        ->join('__IMS_ADDRESS__ area','vm.join_address_id = area.id', 'left')
        ->field('vm.*,pc.name,im.staff_name,area.province_id,area.city_id,area.area_id,area.address')
        ->where($where);
        $list = $model->order($order)->paginate($limit);
        // $count = $model->count();
        $count = $this->alias('vm')
        ->join('__PORTAL_CATEGORY__ pc','vm.type_id = pc.id', 'left')
        ->join('__IMS_MEMBER__ im','vm.user_id = im.id', 'left')
        ->join('__IMS_ADDRESS__ area','vm.join_address_id = area.id', 'left')
        ->where($where)->count();
        $page = $list->render();
        foreach ( $list as $key => $val ) {
            $list[$key]['cover_pic'] = cmf_get_image_url(str_replace("\\","/",$val['cover_pic']));
            $province = Db::name('ims_regions')->where('region_id',$val['province_id'])->value('region_name');
            $city = Db::name('ims_regions')->where('region_id',$val['city_id'])->value('region_name');
            $area = Db::name('ims_regions')->where('region_id',$val['area_id'])->value('region_name');
            $list[$key]['address'] = $province.$city.$area.$val['address'];
        } 
        return ['list'=>$list, 'page'=>$page, 'count'=>$count];
    }

    /**
     * 获取单个会议信息
     * @param array $where 查询条件
     * @return array
     */
    public function meetingInfo($where=array())
    {
        $info = $this->alias('vm')
        ->join('__PORTAL_CATEGORY__ pc','vm.type_id = pc.id', 'left')
        ->join('__IMS_MEMBER__ im','vm.user_id = im.id', 'left')
        ->join('__IMS_ADDRESS__ area','vm.join_address_id = area.id', 'left')
        ->field('vm.*,pc.name,im.staff_name,im.staff_number,area.province_id,area.city_id,area.area_id,area.address')
        ->where($where)->find()->toArray();


        $info['compere_number'] = Db::name('ims_member')->where('id',$info['compere_id'])->value('staff_number'); // 主持人员工工号
        $info['cover_pic'] = cmf_get_image_url(str_replace("\\","/",$info['cover_pic'])); // 处理图片
        $province = Db::name('ims_regions')->where('region_id',$info['province_id'])->value('region_name');
        $city = Db::name('ims_regions')->where('region_id',$info['city_id'])->value('region_name');
        $area = Db::name('ims_regions')->where('region_id',$info['area_id'])->value('region_name');
        $info['address'] = $province.$city.$area.$info['address'];

        // 获取参会人员列表
        $confereeModel = new ImsMeetingJoinModel();
        $info['confereeList'] = $confereeModel->confereeList(['vm_id'=>$info['id'], 'is_vm'=>2]);

        return $info;
    }
}